package com.huike.controller.dictionaries;

import com.huike.dto.DictDatePageDTO;
import com.huike.dto.DictTypeDTO;
import com.huike.dto.DictionariesPageDTO;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.dictionaries.DictionariesService;
import com.huike.vo.DictDateVO;
import com.huike.vo.DictPageVO;
import com.huike.vo.DictionariesVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("system/dict/")
public class DictionariesController {
    @Autowired
    private DictionariesService dictionariesService;

    @GetMapping("/type/list")
    @ApiOperation("字典分页查询")
    public PageResult DictTypeList(DictionariesPageDTO dto) {
        return dictionariesService.selectList(dto);
    }

    @GetMapping("/type/{id}")
    @ApiOperation("根据id查询字典")
    public Result<DictionariesVO> DictionariesById(@PathVariable("id") Long id) {
        DictionariesVO vo = dictionariesService.selectById(id);
        return Result.success(vo);
    }
    @GetMapping("data/type/{status}")
    @ApiOperation("根据状态查询字典标签")
    public Result<List<DictDateVO>>DictionariesStatus(@PathVariable("status") String status) {
        return dictionariesService.selectByStatus(status);
    }
    @GetMapping("/data/list")
    @ApiOperation("字典分页查询")
    public PageResult DictDateList(DictDatePageDTO dto) {
        return dictionariesService.selectDateList(dto);
    }

    @PostMapping("/type")
    @ApiOperation("新增字典功能")
    public Result<String> dictTypeSave(@RequestBody DictPageVO vo) {
         dictionariesService.dictTypeSave(vo);
        return Result.success();
    }
    @DeleteMapping("/type/{ids}")
    @ApiOperation(("删除字典功能"))
    public Result<String> dictTypeDelect(@PathVariable("ids") List<Long> ids){
        dictionariesService.dictTypeDelect(ids);
        return Result.success();
    }

    @PutMapping("/type")
    @ApiOperation("修改字典功能")
    public Result<String> dictTypeUpdate(@RequestBody DictTypeDTO dto) {
        dictionariesService.dictTypeUpdate(dto);
        return Result.success();
    }
    @PostMapping("/data")
    @ApiOperation("新增字典标签功能")
    public Result<String> dictDateSave(@RequestBody DictDateVO vo) {
        dictionariesService.dictDateSave(vo);
        return Result.success();
    }
    @GetMapping("/data/{id}")
    @ApiOperation("根据id查询字典标签功能")
    public Result<DictDateVO> dictDateSelectById(@PathVariable Long id) {
        DictDateVO vo= dictionariesService.dictDateSelectById(id);
        return Result.success(vo);
    }
    @PutMapping("/data")
    @ApiOperation("修改字典标签功能")
    public Result<String> dictTypeUpdate(@RequestBody DictDateVO dto) {
        dictionariesService.dictDateUpdate(dto);
        return Result.success();
    }

    @DeleteMapping("/data/{ids}")
    @ApiOperation(("删除字典功能"))
    public Result<String> dictDateDelect(@PathVariable("ids") List<Long> ids){
        dictionariesService.dictDateDelect(ids);
        return Result.success();
    }
}
